package whu.o2o.adapter;



import whu.o2o.util.Utils;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import whu.o2o.R;

public class SwitchTextAdapter extends BaseAdapter {
	public int publicSelected;
	private Activity mContext;
	private String[] mArray;
	private Drawable mSelectedDrawable;
	private int mTextColor;
	private float mTextSize;
	private int mPaddingSize;

	public SwitchTextAdapter(Activity context, String[] array) {
		mContext = context;
		mArray = array;
		mSelectedDrawable = mContext.getResources().getDrawable(R.drawable.sousuo_sure);
		mSelectedDrawable.setBounds(0, 0, mSelectedDrawable.getMinimumWidth(), mSelectedDrawable.getMinimumHeight());

		mTextSize = mContext.getResources().getDimension(R.dimen.text_normal);
		mTextColor = mContext.getResources().getColor(R.color.text_normal);
		mPaddingSize = Utils.dip2px(mContext, 10);
	}

	@Override
	public int getCount() {
		return mArray.length;
	}

	@Override
	public Object getItem(int position) {
		return mArray[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();

			TextView textView = new TextView(mContext);
			textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
			textView.setTextColor(mTextColor);
			textView.setPadding(mPaddingSize, mPaddingSize, mPaddingSize, mPaddingSize);
			textView.setGravity(Gravity.CENTER_VERTICAL);
			convertView = textView;
			holder.name = (TextView) convertView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (position == publicSelected) {
			holder.name.setCompoundDrawables(null, null, mSelectedDrawable, null);
		} else {
			holder.name.setCompoundDrawables(null, null, null, null);
		}

		holder.name.setText(mArray[position]);

		return convertView;
	}

	static class ViewHolder {
		TextView name;
	}
}
